package cn.wangsy.zhidao.p20170121;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Person {

	private String name;
	private int age;
	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public int getAge() {
		return age;
	}

	public void setAge(int age) {
		this.age = age;
	}

	public static void main(String[] args) {

		List<Person> persons = new ArrayList<Person>();
		Scanner scanner = new Scanner(System.in);
		while(true){
			Person person = new Person();
			System.out.println("请输入姓名：");
			String name = scanner.next();
			System.out.println("请输入年龄：");
			int age = scanner.nextInt();
			
			person.setName(name);
			person.setAge(age);
			persons.add(person);
			
			System.out.println("继续输入：y/n?");
			String cmd = scanner.next();
			if("n".equalsIgnoreCase(cmd)){
				break;
			}
		}
		
		System.out.println("共输入"+persons.size()+"人");
		int sum = 0;
		for(Person p:persons){
			sum += p.getAge();
		}
		System.out.println("平均年龄："+(1.0*sum/persons.size()));
	}

}
